#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
	int fd = open("./test.txt", O_RDONLY);
	if(fd > 0)
	{
		std::cout << "file open success, fd : " << fd << std::endl;
		char buff[1024];
		ssize_t n = read(fd, buff, sizeof(buff) - 1);
		if(n > 0){
			buff[n] = 0;
			std::cout << "read done, message : " << buff << std::endl;
		}else if(n == 0){
			std::cout << "read all data" << std::endl;
		}else{
			std::cout << "read error" << std::endl;
		}
		close(fd);
	}
	return 0;
}
//int main()
//{
//	umask(0000);
//	int fd = open("./test.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
//	if(fd > 0)
//	{
//		std::cout << "file create success, fd : " << fd << std::endl;
//		std::string message = "hello world!!!!";
//		ssize_t n = write(fd, message.c_str(), message.size());
//		if(n < 0)
//			std::cout << "write error\n";
//
//		close(fd);
//	}
//	return 0;
//}
